﻿using Dapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Data;
using XxSystem.FileServer.Cores;

namespace WebAppNote.Controllers
{  
    
    [Route("api/[controller]")]
    [ApiController]
    public class NoteController : ControllerBase
    {
        private IDbConnection con;

        public NoteController(IDbConnection con)
        {
            this.con = con;
        }


        [HttpPost("/write")]
        public long Write(NoteEntity entity) 
        {
            var sql = "INSERT INTO note(title, body, createdBy,created) VALUES(@title, @body, @createdBy, @created)";
            entity.Created = DateTime.Now;
            entity.CreatedBy = 1;
            return con.Execute(sql, entity);
        }
    }
}
